package com.jackeys.piaems.service.impl;

import com.jackeys.piaems.annotation.PassJwt;
import com.jackeys.piaems.dao.CategoryDao;
import com.jackeys.piaems.dto.CategoryDto;
import com.jackeys.piaems.entity.Category;
import com.jackeys.piaems.service.CategoryService;
import com.jackeys.piaems.util.StatusEnumUtil;
import com.jackeys.piaems.vo.ResponseVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName: CategoryServiceImpl
 * @Description: 类别业务层实现类
 * @Author: Jackeys
 * @Date: 2021-06-25 11:10
 * @Version: 1.0
 */
@Slf4j
@Service
@Transactional
public class CategoryServiceImpl implements CategoryService {

    @Autowired
    private CategoryDao categoryDao;

    /**
    * @Name: getAllCategories
    * @Description: 查询所有类别，实现多种类别选择的功能
    * @Param: []
    * @return: com.jackeys.piaems.vo.ResponseVo
    * @Author: Jackeys
    * @Date: 2021/6/25 11:14
    * @Version: 1.0
    */
    @Override
    public ResponseVo getAllCategories() {
        log.debug("=====================================================================");
        log.debug("获取所有类别");
        List<Category> categoryList = categoryDao.getAllCategoryList();
        List<CategoryDto> categoryDtoList = new ArrayList<>();
        if(categoryList==null||categoryList.size()==0){
            log.debug("查询失败：集合为空");
            log.debug("=====================================================================");
            return new ResponseVo(StatusEnumUtil.CATEGORY_GET_FAIL);
        }
        for (Category category : categoryList) {
            categoryDtoList.add(new CategoryDto(category.getId(), category.getName()));
        }
        log.debug("查询成功");
        log.debug("=====================================================================");
        return new ResponseVo(StatusEnumUtil.CATEGORY_GET_SUCCESS).add("categoryList",categoryDtoList);
    }
}
